package com.tanhua.server.controller;

import com.tanhua.manage.domain.vo.PageResult;
import com.tanhua.manage.domain.vo.SettingsVo;
import com.tanhua.manage.domain.vo.UserInfoVoAge;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;

    @GetMapping("/settings")
    public ResponseEntity querySettings(){
        SettingsVo settingsVo = settingsService.querySettings();
        return ResponseEntity.ok(settingsVo);
    }

    /**
     * 保存通知设置
     * @param vo
     * @return
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity updateNotification(@RequestBody SettingsVo vo){
        settingsService.updateNotification(vo);
        return ResponseEntity.ok(null);
    }

    /**
     * 黑名单查询
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(value = "page",defaultValue = "1") Long page,@RequestParam(value = "pagesize",defaultValue = "10") Long pageSize){
        page = page>0?page:1;// 如果页码<=0 查询第1页
        pageSize = pageSize>0?pageSize:10;// 负数处理
        // pageSize限制大小，防止用户查询过多导致系统问题
        pageSize = pageSize<50?pageSize:50;
        PageResult<UserInfoVoAge> pageResult = settingsService.blacklist(page,pageSize);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 移除黑名单
     * @param blackUserId
     * @return
     */
    @DeleteMapping("/blacklist/{blackUserId}")
    public ResponseEntity removeBlackList(@PathVariable("blackUserId") long blackUserId){
        settingsService.removeBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }
    /**
     * 保存陌生人问题
     */
    @PostMapping("/questions")
    public ResponseEntity updateQuestion (@RequestBody Map<String,String> paramMap){

        settingsService.updateQuestion(paramMap);
        return ResponseEntity.ok(null);
    }


}
